Skip to content

feat: Add allSiteIdsByTier and allByEnrollmentAndTier collection meth… - #1569

Merged
sandsinh merged 6 commits into
mainfrom
SITES-43769
Jul 20, 2026
Merged

feat: Add allSiteIdsByTier and allByEnrollmentAndTier collection meth…#1569
sandsinh merged 6 commits into
mainfrom
SITES-43769

Conversation

@sandsinh

@sandsinh sandsinh commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

What

Adds two new collection methods to spacecat-shared-data-access for querying sites by entitlement tier:

  • SiteEnrollmentCollection.allSiteIdsByTier(tier, productCode?) — single JOIN query against site_enrollments/entitlements returning matching siteIds, optionally narrowed to a product code.
  • SiteCollection.allByEnrollmentAndTier(tier, productCode?, options?) — chains through SiteEnrollmentCollection via entityRegistry and batch-fetches full Site objects for those IDs.

Why

Callers need to look up sites by entitlement tier (e.g. PAID, FREE_TRIAL, PLG), optionally scoped to a product code (e.g. LLMO), without fetching every enrollment and filtering in memory.

Testing

Unit and integration tests added for both new methods (site.collection.test.js, site.test.js, site-enrollment.collection.test.js, site-enrollment.test.js).

Related Issues

SITES-43769

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

This PR will trigger a minor release when merged.

sandsinh and others added 2 commits July 19, 2026 01:13
Monorepo uses npm workspaces with a single root lockfile; this
per-package lockfile was added by mistake.
@sandsinh
sandsinh requested a review from MysticatBot July 18, 2026 20:25

@MysticatBot MysticatBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sandsinh,

Verdict: Request changes - one deduplication gap to address before merge.
Complexity: MEDIUM - medium diff, new collection methods following existing patterns.
Changes: Adds tier-based site enrollment lookup methods (allSiteIdsByTier and allByEnrollmentAndTier) with full test coverage (8 files).

Must fix before merge

  1. [Important] Duplicate site IDs not deduplicated before batch fetch - packages/spacecat-shared-data-access/src/models/site-enrollment/site-enrollment.collection.js:79 (details inline)
Non-blocking (2): minor issues and suggestions
  • nit: Inconsistent input validation - allSiteIdsByTier uses if (!tier) while allByEnrollmentAndTier uses if (!hasText(tier)). The falsy check accepts whitespace-only strings; consider aligning to hasText for consistency - site-enrollment.collection.js:59
  • nit: TypeScript declarations for allSiteIdsByProductCode and allByEnrollmentProductCode are added to the .d.ts files but their implementations are not visible in this diff. Confirm these are pre-existing methods getting their missing types backfilled alongside the new code - site-enrollment/index.d.ts:9, site/index.d.ts:66

Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 2m 41s | Cost: $4.78 | Commit: 71632b2245ae3b16aa6e6f6926c90ebf477b7b20
If this code review was useful, please react with 👍. Otherwise, react with 👎.

this.log.error(`[SiteEnrollmentCollection] Failed to query site_enrollments by tier - ${error.message}`, error);
throw new DataAccessError('Failed to query site_enrollments by tier', { entityName: 'SiteEnrollment', tableName: 'site_enrollments' }, error);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): allSiteIdsByTier returns raw (data || []).map((row) => row.site_id) without deduplication. If a site is enrolled in multiple entitlements at the same tier (e.g., two PAID entitlements for different product codes when no productCode filter is supplied), the query returns duplicate site_id values. These duplicates flow into allByEnrollmentAndTier and cause redundant batchGetByKeys lookups - wasted I/O on the same primary keys.

The existing allSiteIdsByProductCode sibling has the same pattern but is less likely to produce duplicates in practice (unique on (site_id, entitlement_id) plus a specific product code narrows to one entitlement per site). Tier is a broader classifier and more likely to hit this.

Fix:

return [...new Set((data || []).map((row) => row.site_id))];

@MysticatBot MysticatBot added ai-reviewed Reviewed by AI complexity:medium AI-assessed PR complexity: MEDIUM labels Jul 18, 2026
sandsinh and others added 2 commits July 20, 2026 13:56
- Dedupe site IDs in allSiteIdsByTier before batch fetch (duplicate rows possible when a site holds multiple entitlements at the same tier without a productCode filter)
- Align allSiteIdsByTier's tier validation to hasText for consistency with allByEnrollmentAndTier

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sandsinh
sandsinh requested a review from MysticatBot July 20, 2026 21:44

@MysticatBot MysticatBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sandsinh,

Verdict: Approve - all prior findings addressed, no new blocking issues.
Complexity: MEDIUM - medium diff, new collection methods following existing patterns.
Changes: Adds tier-based site enrollment lookup methods with deduplication fix and full test coverage (8 files).

Previously flagged, now resolved

  • Duplicate site IDs not deduplicated before batch fetch - now uses [...new Set(...)] in allSiteIdsByTier
  • Inconsistent input validation (!tier vs hasText(tier)) - both methods now use hasText(tier)
  • TypeScript declarations for allSiteIdsByProductCode and allByEnrollmentProductCode backfilled alongside new methods
Non-blocking (1): minor issues and suggestions
  • suggestion: The pre-existing allSiteIdsByProductCode method (line 47) still uses (data || []).map((row) => row.site_id) without Set-based deduplication. The same duplicate-site-ID scenario is possible there. Consider aligning it with the new allSiteIdsByTier pattern in a follow-up - site-enrollment.collection.js:47

Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 1m 43s | Cost: $3.80 | Commit: ecdd326f638c552579cd4ada7212322674976d54
If this code review was useful, please react with 👍. Otherwise, react with 👎.

@sandsinh
sandsinh merged commit 3ac585b into main Jul 20, 2026
6 checks passed
@sandsinh
sandsinh deleted the SITES-43769 branch July 20, 2026 22:51
solaris007 pushed a commit that referenced this pull request Jul 20, 2026
## [@adobe/spacecat-shared-data-access-v4.10.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.9.0...@adobe/spacecat-shared-data-access-v4.10.0) (2026-07-20)

### Features

* Add allSiteIdsByTier and allByEnrollmentAndTier collection meth… ([#1569](#1569)) ([3ac585b](3ac585b))
@solaris007

Copy link
Copy Markdown
Member

🎉 This PR is included in version @adobe/spacecat-shared-data-access-v4.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

jindaliiita pushed a commit that referenced this pull request Jul 21, 2026
#1569)

## What

Adds two new collection methods to `spacecat-shared-data-access` for
querying sites by entitlement tier:

- `SiteEnrollmentCollection.allSiteIdsByTier(tier, productCode?)` —
single JOIN query against `site_enrollments`/`entitlements` returning
matching `siteId`s, optionally narrowed to a product code.
- `SiteCollection.allByEnrollmentAndTier(tier, productCode?, options?)`
— chains through `SiteEnrollmentCollection` via `entityRegistry` and
batch-fetches full `Site` objects for those IDs.

## Why

Callers need to look up sites by entitlement tier (e.g. `PAID`,
`FREE_TRIAL`, `PLG`), optionally scoped to a product code (e.g. `LLMO`),
without fetching every enrollment and filtering in memory.

## Testing

Unit and integration tests added for both new methods
(`site.collection.test.js`, `site.test.js`,
`site-enrollment.collection.test.js`, `site-enrollment.test.js`).

## Related Issues

SITES-43769

---------

Co-authored-by: Sandesh Sinha <sandsinh@Sandeshs-MacBook-Pro.local>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
jindaliiita pushed a commit that referenced this pull request Jul 21, 2026
## [@adobe/spacecat-shared-data-access-v4.10.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.9.0...@adobe/spacecat-shared-data-access-v4.10.0) (2026-07-20)

### Features

* Add allSiteIdsByTier and allByEnrollmentAndTier collection meth… ([#1569](#1569)) ([3ac585b](3ac585b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-reviewed Reviewed by AI complexity:medium AI-assessed PR complexity: MEDIUM released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants